import os
import shutil
from pathlib import Path
import pytest
from config.config import RESULT_PATH, REPORT_PATH, TESTCASE_PATH, PROJECT_PATH


if __name__ == "__main__":
    # 检查测试结果路径是否存在，若存在，则删除该目录，否则pass，然后重新创建该目录
    # 目的是确保RESULT_PATH目录为空
    try:
        os.listdir(RESULT_PATH)
    except FileNotFoundError as e:
        pass
    else:
        shutil.rmtree(RESULT_PATH)
    finally:
        os.mkdir(RESULT_PATH)
    pytest.main(["-v", "--alluredir", f"{RESULT_PATH}", f"{Path(TESTCASE_PATH).joinpath('test_interface.py')}"])
    os.system(f"cp {Path(PROJECT_PATH).joinpath('environment.properties')} {RESULT_PATH} && "
              f"allure generate {RESULT_PATH} -o {REPORT_PATH} --clean")
